#! /usr/bin/env python

"""catch stdout print content, from this:
http://ciniao.me/article.php?id=24&page=1"""

import sys
import time

class MyOutput():
    def __init__(self, fd):
        self.formateTime()
        self.out = fd
        self.newLine = True
    def formateTime(self):
        return time.strftime("%H:%M:%S ", time.localtime())
    def write(self, s):
        if self.newLine:
            self.out.write(self.formateTime())
            self.newLine = False
        self.out.write(s)
        if s.endswith("\n"):
            self.newLine = True
    def flush(self):
        self.out.flush()

sys.stdout = MyOutput(sys.stdout)

print "Program begin:"

mylist = range(1, 6)

# print time.strftime("%H:%M:%S ", time.localtime()), " mylist:", mylist

print "prev: ", mylist

mylist.reverse()

print "after: ", mylist

time.sleep(3)

print "Program end."


